var t = require;
var e = module;
var o = exports;
var i, n = this && this.__extends || (i = function(t, e) {
    return (i = Object.setPrototypeOf || {
        __proto__: []
    }
    instanceof Array &&
    function(t, e) {
        t.__proto__ = e
    } ||
    function(t, e) {
        for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
    })(t, e)
},
function(t, e) {
    function o() {
        this.constructor = t
    }
    i(t, e),
    t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
}),
a = this && this.__decorate ||
function(t, e, o, i) {
    var n, a = arguments.length,
    r = a < 3 ? e: null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);
    else for (var s = t.length - 1; s >= 0; s--)(n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
    return a > 3 && r && Object.defineProperty(e, o, r),
    r
};
Object.defineProperty(o, "__esModule", {
    value: !0
});
var r = t("CarConstant"),
s = t("GlobalUserData"),
l = t("Hint"),
c = t("BroadCastMessage"),
d = t("Util"),
h = t("HallConstant"),
p = t("GoldFlyAnim"),
u = t("SellItem"),
f = cc._decorator,
m = f.ccclass,
_ = f.property,
y = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.pfb_sellItem = null,
        e.pfb_goldfly = null,
        e.icon_gold = null,
        e.lab_gold = null,
        e.lab_diamond = null,
        e.lab_sellGold = null,
        e.node_iconSellGold = null,
        e.scrollContent = null,
        e.arrNode_starCheck = new Array(5),
        e._hallControl = null,
        e.arrItemsControl = [],
        e._curSellType = null,
        e.isShowCustomAd = !1,
        e.nSellGoldTotal = 0,
        e.nCurCheckStar = 0,
        e
    }
    return n(e, t),
    e.prototype.onLoad = function() {},
    e.prototype.onDestroy = function() {},
    e.prototype.onEnable = function() {
        d.Util.event_dispatcher.register(this),
        d.Util.hideSingleCustomAd(),
        d.Util.showInterstitialAd(null, this.onshowSingleCustomAd.bind(this),
        function() {
            d.Util.show_matrixAd()
        })
    },
    e.prototype.onshowSingleCustomAd = function() {
        d.Util.showLeftSingleCustomAd(),
        d.Util.showRightSingleCustomAd()
    },
    e.prototype.onDisable = function() {
        d.Util.event_dispatcher.remove(this),
        d.Util.hideLeftSingleCustomAd(),
        d.Util.hideRightSingleCustomAd(),
        d.Util.showSingleCustomAd(cc.v2(150, -60))
    },
    e.prototype.init = function(t) {
        this._hallControl = t,
        this.onSetSellGold(!1, 0),
        this.onSetOwnGold(!1),
        this.lab_diamond.string = s.default.nDiamond.toString()
    },
    e.prototype.onSetOwnGold = function(t) {
        var e = this;
        if (t) {
            this.icon_gold.stopAllActions();
            var o = cc.tween().to(.1, {
                y: 20
            },
            {
                easing: "sineIn"
            }),
            i = cc.tween().to(.1, {
                y: -10
            },
            {
                easing: "sineOut"
            }),
            n = cc.tween().sequence(i, o);
            cc.tween(this.icon_gold).repeatForever(n).start();
            var a = s.default.nGlod,
            r = Math.floor((s.default.nGlod - a) / 10),
            l = function() {
                if ((a += r) >= s.default.nGlod) return e.icon_gold.stopAllActions(),
                e.icon_gold.y = 0,
                e.lab_gold.node.stopAllActions(),
                void(e.lab_gold.string = d.Util.transformGoldStr(s.default.nGlod));
                e.lab_gold.string = d.Util.transformGoldStr(a),
                cc.tween(e.lab_gold.node).delay(.2).call(function() {
                    l()
                }).start()
            };
            l()
        } else this.lab_gold.string = d.Util.transformGoldStr(s.default.nGlod)
    },
    e.prototype.onSetSellGold = function(t, e) {
        t ? this.nSellGoldTotal += e: this.nSellGoldTotal -= e,
        this.lab_sellGold.string = d.Util.transformGoldStr(this.nSellGoldTotal)
    },
    e.prototype.updateView = function(t, e) {
        this._curSellType = t,
        this.node.active = !0;
        for (var o = 0; o < this.arrNode_starCheck.length; o++) this.arrNode_starCheck[o].active = !1;
        if (this.nSellGoldTotal = 0, this.onSetSellGold(!1, 0), e.length > 2 && (this.scrollContent.height = 209 * (Math.floor(e.length / 4) + 1) + 20), e.length > this.arrItemsControl.length) {
            for (o = 0; o < e.length; ++o) if (this.arrItemsControl[o]) this.arrItemsControl[o].updateItem(o, e[o]);
            else {
                var i = o % 4,
                n = Math.floor(o / 4),
                a = cc.v3(20 + 222 * i, -20 - 209 * n, 0);
                this.arrItemsControl.push(this.createSellItem(this.scrollContent, o, e[o], a))
            }
        } else for (o = 0; o < this.arrItemsControl.length; ++o) e[o] ? this.arrItemsControl[o].updateItem(o, e[o]) : this.arrItemsControl[o].onActive(!1)
    },
    e.prototype.createSellItem = function(t, e, o, i) {
        var n = cc.instantiate(this.pfb_sellItem);
        t.addChild(n);
        var a = n.getComponent(u.default);
        return a.init(this),
        a.updateItem(e, o),
        n.position = i,
        a
    },
    e.prototype.onBtnBack = function() {
        this.playAudio(h.Audio_ID.btn_click),
        this.node.active = !1
    },
    e.prototype.onBtnCheckStar = function(t, e) {
        this.playAudio(h.Audio_ID.btn_click);
        var o = Number(e) - 1;
        this.arrNode_starCheck[o].active = !this.arrNode_starCheck[o].active,
        this.onStarCheckItem(this.arrNode_starCheck[o].active, o + 1)
    },
    e.prototype.onBtnSell = function() {
        this.playAudio(h.Audio_ID.btn_click),
        this.nSellGoldTotal > 0 && this.onSellHandle() ? (s.default.saveGoldData(!0, this.nSellGoldTotal), this.playGetGoldAnim(), this._hallControl.onSetOwnGold(), this._hallControl._assemblyView.updateScrolView(), this.updateView(this._curSellType, this._hallControl._assemblyView.getAssemblyData(this._curSellType)), this._hallControl._assemblyView.updateAttributeItemState(), l.default.show("出售成功！")) : l.default.show("出售失败，请稍后重试")
    },
    e.prototype.onSellHandle = function() {
        for (var t = [], e = [], o = [], i = [], n = 0; n < this.arrItemsControl.length; n++) {
            var a = this.arrItemsControl[n].getSellData();
            if (a) switch (a.type) {
                case r.Basics_Items_Type.body:
                    t.push(a);
                break;
                case r.Basics_Items_Type.wheel:
                    e.push(a);
                break;
                case r.Basics_Items_Type.weapon:
                    o.push(a);
                break;
                case r.Basics_Items_Type.tools:
                    i.push(a);
            }
        }
        return t.length > 0 && s.default.saveOwnCarBodyData(!1, t, !0),
        e.length > 0 && s.default.saveOwnWheelData(!1, e, !0),
        o.length > 0 && s.default.saveOwnWeaponData(!1, o, !0),
        i.length > 0 && s.default.saveOwnToolsData(!1, i, !0),
        !0
    },
    e.prototype.onStarCheckItem = function(t, e) {
        for (var o = 0; o < this.arrItemsControl.length; o++) this.arrItemsControl[o].onCheck(t, e)
    },
    e.prototype.playGetGoldAnim = function() {
        var t = this;
        this.playAudio(h.Audio_ID.get_gold);
        var e = cc.v3(200, cc.winSize.height, 0);
        d.Util.AnimFly(p.Fly_Type.Gold, this.pfb_goldfly, this.node_iconSellGold, e,
        function() {
            t.onSetOwnGold(!0)
        },
        function() {})
    },
    e.prototype.playAudio = function(t) {
        this._hallControl ? this._hallControl.playAudio(t) : c.default.getInstance().SendMessage(h.Broadcast_Func.Audio, t)
    },
    a([_(cc.Prefab)], e.prototype, "pfb_sellItem", void 0),
    a([_(cc.Prefab)], e.prototype, "pfb_goldfly", void 0),
    a([_(cc.Node)], e.prototype, "icon_gold", void 0),
    a([_(cc.Label)], e.prototype, "lab_gold", void 0),
    a([_(cc.Label)], e.prototype, "lab_diamond", void 0),
    a([_(cc.Label)], e.prototype, "lab_sellGold", void 0),
    a([_(cc.Node)], e.prototype, "node_iconSellGold", void 0),
    a([_(cc.Node)], e.prototype, "scrollContent", void 0),
    a([_(cc.Node)], e.prototype, "arrNode_starCheck", void 0),
    a([m], e)
} (cc.Component);
o.default = y